package gold.digger;

import gold.utils.InputUtil;

/**
 * Created by fanzhenyu02 on 2021/12/10.
 * common problem solver template.
 */
public class LC2016 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int maximumDifference(int[] nums) {
            int prevMin = nums[0], ans = -1;
            for (int i = 1; i < nums.length; i++) {
                ans = Math.max(ans, nums[i] - prevMin);
                prevMin = Math.min(prevMin, nums[i]);
            }

            return ans <= 0 ? -1 : ans;
        }
    }

    public void run() {
        Solution solution = new Solution();
        System.out.println(solution.maximumDifference(InputUtil.toIntegerArray("[7,1,5,4]")));
        System.out.println(solution.maximumDifference(InputUtil.toIntegerArray("[9,4,3,2]")));
        System.out.println(solution.maximumDifference(InputUtil.toIntegerArray("[1,5,2,10]")));
    }

    public static void main(String[] args) throws Exception {
        LC2016 an = new LC2016();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
